#include<iostream>

using namespace std;

const int N=1e5+10;
typedef long long LL;

LL n,m,p,w[N];

struct node
{
	LL l,r;
	LL sum,plz,mlz;
}tr[N*4];

inline void build(LL u,LL l,LL r,LL w[])
{
	tr[u].l=l;
	tr[u].r=r;
	tr[u].mlz=1;
	if(l==r)
	{
		tr[u].sum=w[l]%p;
		return;
	}
	LL mid=l+r>>1;
	build(u<<1,l,mid,w);
	build(u<<1|1,mid+1,r,w);
	tr[u].sum=(tr[u<<1].sum+tr[u<<1|1].sum)%p;
}

inline void push_down(LL u)
{
	tr[u<<1].sum=(tr[u].mlz*tr[u<<1].sum+tr[u].plz*(tr[u<<1].r-tr[u<<1].l+1))%p;
	tr[u<<1|1].sum=(tr[u].mlz*tr[u<<1|1].sum+tr[u].plz*(tr[u<<1|1].r-tr[u<<1|1].l+1))%p;
	tr[u<<1].mlz=(tr[u].mlz*tr[u<<1].mlz)%p;
	tr[u<<1|1].mlz=(tr[u].mlz*tr[u<<1|1].mlz)%p;
	tr[u<<1].plz=(tr[u].mlz*tr[u<<1].plz+tr[u].plz)%p;
	tr[u<<1|1].plz=(tr[u].mlz*tr[u<<1|1].plz+tr[u].plz)%p;
	tr[u].mlz=1,tr[u].plz=0;
}

inline void modify1(LL u,LL l,LL r,LL k)
{
	if(tr[u].l>=l && tr[u].r<=r)
	{
		tr[u].sum=(tr[u].sum*k)%p;
		tr[u].mlz=(tr[u].mlz*k)%p;
		tr[u].plz=(tr[u].plz*k)%p;
		return;
	}
	push_down(u);
	LL mid=tr[u].l+tr[u].r>>1;
	if(mid>=l) modify1(u<<1,l,r,k);
	if(mid<r) modify1(u<<1|1,l,r,k);
	tr[u].sum=(tr[u<<1].sum+tr[u<<1|1].sum)%p;
}

inline void modify2(LL u,LL l,LL r,LL k)
{
	if(tr[u].l>=l && tr[u].r<=r)
	{
		tr[u].sum=tr[u].sum+(tr[u].r-tr[u].l+1)*k;
		tr[u].plz=tr[u].plz+k;
		return;
	}
	push_down(u);
	LL mid=tr[u].l+tr[u].r>>1;
	if(mid>=l) modify2(u<<1,l,r,k);
	if(mid<r) modify2(u<<1|1,l,r,k);
	tr[u].sum=(tr[u<<1].sum+tr[u<<1|1].sum)%p;
}

inline long long query(LL u,LL l,LL r)
{
	if(tr[u].l>=l && tr[u].r<=r)
	{
		return tr[u].sum;
	}
	push_down(u);
	LL mid=tr[u].l+tr[u].r>>1;
	long long num=0;
	if(mid>=l) num=(num+query(u<<1,l,r))%p;
	if(mid<r) num=(num+query(u<<1|1,l,r))%p;
	return num;
}

int main()
{
	cin>>n>>m>>p;
	for(int i=1;i<=n;i++) scanf("%lld",&w[i]);
	build(1,1,n,w);
	while(m--)
	{
		int t;
		scanf("%d",&t);
		if(t==1)
		{
			LL x,y,k;
			scanf("%lld%lld%lld",&x,&y,&k);
			modify1(1,x,y,k);
		 } 
		 else if(t==2)
		 {
		 	LL x,y,k;
		 	scanf("%lld%lld%lld",&x,&y,&k);
		 	modify2(1,x,y,k);
		 }
		 else
		 {
		 	LL x,y;
		 	scanf("%lld%lld",&x,&y);
		 	cout<<query(1,x,y)<<endl;
		 }
	}
	return 0;
}
